package com.lin.filegraph.utils.parser.astvisitor;

import com.lin.filegraph.utils.parser.simpleast.SimpleASTHelper;
import com.lin.filegraph.utils.parser.node.JMethodNode;
import org.eclipse.jdt.core.dom.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: linhuaixu
 * @time: 2023/5/18 14:15
 */
public class MethodQuoteVisitor extends ASTVisitor {

    ASTNode methodASTNode = null;
    JMethodNode methodNode = null;
    private List<String> listOfQuoteTypes = new ArrayList<>();

    public MethodQuoteVisitor(JMethodNode methodNode) {
        // TODO Auto-generated constructor stub
        this.methodASTNode = methodNode.getAstNode();
        this.methodNode = methodNode;
    }

    @Override
    public boolean visit(VariableDeclarationStatement node) {
        if (node.getType() != null && node.getType().resolveBinding() != null) {
            ITypeBinding typeBinding = node.getType().resolveBinding();
            String typeName = typeBinding.getBinaryName();
            if (SimpleASTHelper.isTypeExist(typeName, methodNode.getRoot())) {
                listOfQuoteTypes.add(typeName);
            }
        }
        return false;
    }

    @Override
    public boolean visit(TypeDeclaration node) {
        return false;
    }

    @Override
    public boolean visit(EnumDeclaration node) {
        return false;
    }

    @Override
    public boolean visit(AnonymousClassDeclaration node) {
        return false;
    }

    public void traverse() {
        methodASTNode.accept(this);
    }

    public List<String> getListOfQuoteTypes() {
        return listOfQuoteTypes;
    }
}
